package cn.edu.fzu.homemaking.domain.handler;

import cn.edu.fzu.homemaking.domain.enums.OrderStatusEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author jiebin
 * @Date 2023/4/6
 */
public class OrderStatusEnumHandler extends BaseTypeHandler<OrderStatusEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, OrderStatusEnum orderStatusEnum, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i, orderStatusEnum.getValue());
    }

    @Override
    public OrderStatusEnum getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return OrderStatusEnum.parse(resultSet.getInt(s));
    }

    @Override
    public OrderStatusEnum getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return OrderStatusEnum.parse(resultSet.getInt(i));
    }

    @Override
    public OrderStatusEnum getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return OrderStatusEnum.parse(callableStatement.getInt(i));
    }
}
